<template>
	<view class="content_view">
		<u-navbar title-color="#FFFFFF" height="48" back-icon-color="#FFFFFF" :border-bottom="false" :is-fixed="true"
			title="维保详情"></u-navbar>
		<uc-content :loading="loading">
			<view class="list-item" v-if="abnormalPic">
				<view class="list-img">
					<view class="text">隐患图片:</view>
					<view class="img">
						<u-image width="50%" height="450rpx" :src="abnormalPic"></u-image>
					</view>
				</view>
			</view>
			<view class="list-item">
				<view class="list-bottom">
					<view>工单名称:</view>
					<view>{{maintenanceInfo.name}}</view>
				</view>
			</view>
			<view class="list-item">
				<view class="list-bottom">
					<view>设备名称:</view>
					<view>{{maintenanceInfo.equipmentName}}</view>
				</view>
			</view>
			<view class="list-item">
				<view class="list-bottom">
					<view>所属企业:</view>
					<view>{{maintenanceInfo.enterpriseName}}</view>
				</view>
			</view>
			<view class="list-item">
				<view class="list-bottom">
					<view>所属区域:</view>
					<view>{{maintenanceInfo.regionName}}</view>
				</view>
			</view>
			<view class="list-item">
				<view class="list-bottom">
					<view>故障描述:</view>
					<view>{{maintenanceInfo.remark}}</view>
				</view>
			</view>
			<view class="list-item">
				<view class="list-bottom">
					<view>上报人联系电话:</view>
					<view>{{maintenanceInfo.reportPersonTel}}</view>
				</view>
			</view>
			<view class="list-item">
				<view class="list-bottom">
					<view>当前状态:</view>
					<view class="u-type-success">{{maintenanceInfo.statusStr}}</view>
				</view>
			</view>
			<view class="list-item">
				<view class="list-bottom">
					<view>整改期限:</view>
					<view class="u-type-success">{{maintenanceInfo.deadline | dateFormat}}</view>
				</view>
			</view>
			<view class="list-item" v-if="maintenanceInfo.status==16">
				<view class="list-bottom">
					<view>申请整改时间:</view>
					<view class="u-type-success">{{maintenanceInfo.examineTime | dateFormat}}</view>
				</view>
			</view>
			<view class="list-item"
				v-if="maintenanceInfo.status==5||maintenanceInfo.completeUrl">
				<view class="list-img">
					<view class="text">完成图片:</view>
					<view class="img">
						<u-image v-if="completeUrl" width="50%" height="450rpx"
							:src="completeUrl+'?x-oss-process=style/zip_pic'" mode="aspectFit">
							<u-loading slot="loading"></u-loading>
						</u-image>
						<u-image v-else width="50%" height="450rpx" :src="completeUrl+'?x-oss-process=style/zip_pic'"
							mode="aspectFit" @click="uploadPic">
							<u-loading slot="loading"></u-loading>
						</u-image>
					</view>
				</view>
			</view>
			<view class="list-item">
				<view>
					<u-button @click="confirmWorkOrder(maintenanceInfo.ucId)" type="primary"
						v-if="maintenanceInfo.status==1" class="btn">确认收到</u-button>
				</view>
				<view v-if="maintenanceInfo.status==2">
					<view v-if="!maintenanceInfo.handle">当前在电子围栏之外，请前往消灾企业进行确认</view>
					<u-button @click="startChangeStatus(maintenanceInfo.ucId)" type="primary"
						:disabled="!maintenanceInfo.handle" class="btn">到场确认</u-button>
				</view>
				<!-- 
				<view v-if="maintenanceInfo.status==2">
					<view v-if="!maintenanceInfo.handle">当前在电子围栏之外，请前往消灾企业进行确认</view>
					<u-button @click="startChangeStatus(maintenanceInfo.ucId)" type="primary"  style="width: 100%;">到场确认</u-button>
				</view> -->
				<view>
					<u-button @click="directDisposal(maintenanceInfo.ucId)" type="primary"
						v-if="maintenanceInfo.status==3" class="btn">现场处置</u-button>
				</view>
				<view>
					<u-button @click="feedback(maintenanceInfo.ucId)" type="primary" v-if="maintenanceInfo.status==3"
						class="btn">采购沟通</u-button>
				</view>
				<view>
					<u-button @click="communicationFinishBecomeContinue(maintenanceInfo.ucId)" type="primary"
						v-if="maintenanceInfo.status==13" class="btn">沟通完成</u-button>
				</view>
				<view>
					<u-button type="primary" disabled v-if="isBuy" class="btn">物料购买中......</u-button>
				</view>
				<view>
					<u-button @click="Reporting(maintenanceInfo.ucId)" type="primary" v-if="maintenanceInfo.status==3"
						class="btn">反馈整改时间</u-button>
				</view>
				<view>
					<u-button @click="workOrderReturn(maintenanceInfo.ucId)" type="error"
						v-if="maintenanceInfo.status==3" class="btn">工单退回</u-button>
				</view>
				<view>
					<u-button @click="uploadPic" type="primary" v-if="maintenanceInfo.status==5&&completeUrl==null"
						class="btn">上传完成图片</u-button>
				</view>
				<view>
					<u-button @click="confirmEndChangeStatus" type="primary"
						v-if="maintenanceInfo.status==5&&completeUrl!=null"
						style="width: 99%;margin-top: 15px; margin-bottom: 20px;">提交</u-button>
				</view>
				<view>
					<u-button @click="agreeExamineTime" type="primary"
						v-if="maintenanceInfo.status==16" class="btn">同意整改时间</u-button>
				</view>
				<!-- 监督员审核整改时间 -->
				<view>
					<u-button @click="checkExamineTime" type="primary"
						v-if="maintenanceInfo.status==16" class="btn">审核整改时间</u-button>
				</view>
				<view>
					<u-button @click="examineConfirm" type="primary"
						v-if="maintenanceInfo.status==8" class="btn">通过审核</u-button>
				</view>
				<view>
					<u-button @click="unapprovedSubmit" type="primary"
						v-if="maintenanceInfo.status==8" class="btn">审核不通过</u-button>
				</view>
				<view>
					<u-button @click="delayCheck" type="primary"
						v-if="maintenanceInfo.status==9" class="btn">延期审核</u-button>
				</view>
			</view>
		</uc-content>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				loading: false,
				maintenanceInfo: {
					ucId: ''
				},
				fileList: [],
				hidden: false,
				hidden2: true,
				location: true,
				completeUrl: null,
				abnormalPic: null,
				isBuy: false,
			}
		},
		onLoad(e) {
			this.ucId = e.ucId
		},
		onShow() {
			this.initView(this.ucId)
		},
		methods: {
			initView(val) {
				//获取地址信息上传内容
				window.native.getLocation(res => {
					this.utils.request("/api/admin/user/reportUserLocation", {
						location: res.data.addr,
						longitude: res.data.longitude,
						latitude: res.data.latitude
					}, "post", "app", true).then(res => {
						console.log(res)
					}).catch(error => {
						console.log(error)
					})
				})
				this.loading = true
				this.maintenanceInfo = {}
				this.pageNum = 0
				this.getInWorkOrderVo(val)
			},
			getInWorkOrderVo(val) {
				this.utils.request("/api/app/workOrder/getInWorkOrderVo", {
					ucId: val
				}, "post", "app", true).then(res => {
					this.maintenanceInfo = res.data
					if (res.data.status == 4 || res.data.status == 10 || res.data.status == 11 || res.data
						.status == 12) {
						this.isBuy = true
					}
					if (this.maintenanceInfo.completeUrl != null) {
						this.completeUrl = this.maintenanceInfo.completeUrl
					}
					if (this.maintenanceInfo.abnormalPic != null) {
						this.abnormalPic = this.maintenanceInfo.abnormalPic
					}
					this.loading = false
				}).catch(error => {
					console.log(error)
				})
			},
			Reporting() {
				uni.navigateTo({
					url: '/pages/index/workorder/maintenance/rectificationTime?ucId=' + this.maintenanceInfo.ucId,
				})
			},
			feedback() {
				uni.navigateTo({
					url: '/pages/index/workorder/maintenance/feedback?ucId=' + this.maintenanceInfo.ucId,
				})
			},
			directDisposal(val) {
				this.utils.request("/api/app/workOrder/directDisposal", {
					ucId: val
				}, "post", "app", true).then(res => {
					this.getInWorkOrderVo(this.ucId)
				}).catch(error => {
					console.log(error)
				})
			},
			confirmWorkOrder(val) {
				this.utils.request("/api/app/workOrder/confirmWorkOrder", {
					ucId: val
				}, "post", "app", true).then(res => {
					this.getInWorkOrderVo(this.ucId)
				}).catch(error => {
					console.log(error)
				})
			},
			startChangeStatus(val) {
				this.utils.request("/api/app/workOrder/startChangeStatus", {
					ucId: val
				}, "post", "app", true).then(res => {
					this.getInWorkOrderVo(this.ucId)
				}).catch(error => {
					console.log(error)
				})
			},
			communicationFinishBecomeContinue(val) {
				this.utils.request("/api/app/workOrder/communicationFinishBecomeContinue", {
					ucId: val
				}, "post", "app", true).then(res => {
					this.getInWorkOrderVo(this.ucId)
				}).catch(error => {
					console.log(error)
				})
			},
			workOrderReturn(val) {
				uni.navigateTo({
					url: "/pages/index/workorder/maintenance/returnDescribe?ucId=" + val
				})
			},
			confirm() {
				let userInfo = this.$store.getters.userInfo
				window.native.camera({
					type: 1,
					ucId: this.maintenanceInfo.ucId,
					userId: userInfo.ucId
				})
				this.getInWorkOrderVo(this.ucId)
			},
			//提交本次任务
			test(data, index, lists, name) {
				console.log(data)
				this.maintenanceInfo.completeUrl = data.data
				this.$refs.uUpload.remove(1)
				console.log(this.maintenanceInfo.completeUrl)
				this.confirmEndChangeStatus()
			},
			confirmEndChangeStatus() {
				this.maintenanceInfo.completeUrl = this.completeUrl
				this.utils.request("/api/app/workOrder/confirmEndChangeStatus", this.maintenanceInfo, "post", "app", true)
					.then(res => {
						uni.navigateTo({
							url: '/pages/index/workorder/maintenance/list',
						})
					}).catch(error => {
						console.log(error)
					})
			},
			uploadPic() {
				window.native.h5Camera()
				window.native.getUri(res => {
					this.completeUrl = res.uri
				})
			},
			// 同意整改时间
			agreeExamineTime() {
				const form = {
					ucId: this.ucId,
					fireAuditTime: this.maintenanceInfo.examineTime,
					fireAuditOpinion: '同意整改时间'
				}
				this.utils.request("/api/app/workOrder/fireAuditTime", form, "post", "app", true).then(
					res => {
						uni.navigateTo({
							url: '/pages/index/workorder/maintenance/list',
						})
					}).catch(error => {
					console.log(error)
				})
			},
			// 审核整改时间
			checkExamineTime() {
				uni.navigateTo({
					url: '/pages/index/workorder/maintenance/checkExamineTime?ucId=' + this.ucId,
				})
			},
			// 通过审核
			examineConfirm() {
				this.utils.request("/api/app/workOrder/orderUltimateEnd", {
					ucId: this.ucId
				}, "post", "app", true).then(res => {
					uni.navigateTo({
						url: '/pages/index/workorder/maintenance/list',
					})
				}).catch(error => {
					console.log(error)
				})
			},
			// 审核不通过
			unapprovedSubmit() {
				this.utils.request("/api/app/workOrder/unapproved", {
					ucId: this.ucId
				}, "post", "app", true).then(res => {
					uni.navigateTo({
						url: '/pages/index/workorder/maintenance/list',
					})
				}).catch(error => {
					console.log(error)
				})
			},
			// 延期审核
			delayCheck() {
				uni.navigateTo({
					url: '/pages/index/workorder/maintenance/delayCheck?ucId=' + this.ucId,
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import "@/uview-ui/libs/css/style.components.scss";

	.list-item {
		padding: 20rpx 40rpx;
		background-color: #fff;
		border-bottom: #999999 1px dashed;

		.list-bottom {
			display: flex;
			margin-top: 10rpx;
			font-size: 28rpx;
			justify-content: space-between;
			color: #333;
		}

		.list-center {
			margin-top: 20rpx;
			font-size: 28rpx;
			color: #999999;
		}

		.list-img {
			display: flex;
			margin-top: 10rpx;
			font-size: 28rpx;
			color: #333;

			.text {
				flex: 1;
			}

			.img {
				flex: 3;
			}
		}
	}

	.btn {
		width: 99%;
		margin-top: 3px;
	}
</style>
